<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Microsoft Edge</title>
    <style>
        * {margin: 0px;padding: 0px;}
        html, body {height: 100%;width: 100%;}
        * {background: transparent;}
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
        }

        body>div.input {
            display: flex;
            width: 50%;
            height: 10%;
            max-height: 47px;
            /*height: 2em;*/
            font-size: 1.3em;
            border-radius: 25px;
            border: none;
            padding: 4px 25px 5px 25px;
            align-items: center;
            justify-content: space-between;
            border: 2px solid #6f6f6f50;
            backdrop-filter: saturate(1.3);
            box-shadow: 1px 3px 8px #00000045;
        }

        body>div.input>input {
            font-size: 1em;
            border: none;
            height: 100%;
            width: 90%;
            color: #7f7f7f;
        }

        body>div.input>input:focus {outline: none;}
        body>div.logo {
            width: 100%;
            height: 12%;
            max-height: 75px;
            background-image: url('Bing.svg');
            background-size: contain;
            background-repeat: no-repeat;
            background-position: 50% 50%;
            margin-bottom: 30px;
            margin-top:-13%;
        }
    </style>
</head>

<body>
    <div class="logo"></div>
    <div class="input">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#5F6368">
            <path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" />
        </svg>
        <input type="text" onkeyup="handleKeyPress(event)" placeholder="">
    </div>
    <script>
        document.getElementsByClassName('input')[0].getElementsByTagName('input')[0].placeholder = window.parent.i18next.t('edge.window.tool.input.placeholder');
        function handleKeyPress(event) {
            if (event.keyCode === 13) {
                let inputValue = event.target.value;
                if (isSearchQuery(inputValue)) {
                    searchInBing(inputValue);
                } else {
                    navigateToURL(inputValue);
                }
            }
        }
        function isSearchQuery(value) {
            // 正则用来验证大部分常见的URL格式，包括以"http://"、"https://"或"ftp://"开头的URL
            var urlPattern = /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/;
            return !urlPattern.test(value);
        }
    
        function searchInBing(query) {
            var encodedQuery = encodeURIComponent(query);
            window.location = 'https://bing.com/search?q=' + encodedQuery;
            apps.edge.rename(query);
        }
    
        function navigateToURL(url) {
            if (!/^https?:\/\//.test(url)) {
                url = 'http://' + url;
            }
            window.location = url;
            apps.edge.rename(url);
        }
    </script>
</body>
</html>